const path = require('path')
const sql = require('../module/index')
const md5 = require('md5')
// const session =require('express-session')
const register = {

}
register.views = (req, res) => {
    res.sendFile(path.resolve(__dirname, '../views/register.html'))
}
register.register = async (req, res) => {
    let { user, cipher } = req.body
    let str = `SELECT * FROM userinfo WHERE username='${user}'`
    let [data] = await sql.query(str)
    if (data.length > 0) {
        res.json({
            code: 40000,
            message: '注册失败'
        })
    } else {
        let str = `INSERT into userinfo(username,password) VALUES('${user}','${md5(cipher)}')`
        let [data] = await sql.query(str)
        if (data.affectedRows == 1) {
            res.json({
                code: 20000,
                message: '注册成功'
            })
        }

    }
}
module.exports = register